package com.noble.glamour.module.logic.config;

import com.noble.glamour.bean.center.user.detail.UserDetail;
import com.noble.glamour.bean.center.user.light.UserLightList;
import com.noble.glamour.bean.my.GiftsList;
import com.noble.library.base.bean.BaseData;
import com.noble.library.host.Hosts;
import com.noble.library.third.ThirdConstant;
import com.noble.meether.chat.ui.agora.act.bean.Accept;
import com.noble.meether.chat.ui.agora.act.bean.ChatStatus;
import com.noble.meether.chat.ui.agora.act.bean.LabelList;
import com.noble.meether.chat.ui.agora.act.bean.RtcComplainReasons;
import com.noble.meether.chat.ui.agora.act.bean.RtcProps;
import com.noble.meether.chat.ui.system.bean.SysNoticeList;
import com.noble.meether.fragment.rob.bean.RobList;
import com.noble.meether.logic.common.bean.Server;
import com.noble.meether.logic.common.bean.Setting;
import com.noble.meether.logic.common.bean.Updata;
import com.noble.meether.logic.login.LoginResult;
import com.noble.meether.logic.media.UpLoadResult;
import com.noble.meether.logic.offline.bean.OfflineMsg;
import com.noble.meether.pay.bean.Pay;
import com.noble.meether.ui.diamond.bean.DiamondList;
import com.noble.meether.ui.invite.bean.InviteDeclareList;
import com.noble.meether.ui.invite.detail.bean.InviteDetailList;
import com.noble.meether.ui.point.bean.PointList;
import com.noble.meether.ui.vip.bean.PrivilegeList;
import com.noble.meether.ui.vip.bean.VipList;
import com.noble.meether.ui.wallet.detail.bean.IncomeList;

import java.util.Map;

/**
 * 管理常用的Url参数信息
 */
public enum UrlParam {
    // ========================= 服务端指派消息服务器 ==============
    reqMsgServer(Hosts.FATE_IT_GO, "v1/sys_server/", Server.class, true),

    // ========================= 遇见Ta： 接口 ==============
    reqSysMessage(Hosts.FATE_IT_GO, "v1/sys_msg/all", SysNoticeList.class, false),    // 获取系统消息
    reqMyService(Hosts.FATE_IT_GO, "v1/user_detail/service", null, false),    // 获取用户专属客服
    reqSettingAll(Hosts.FATE_IT_GO, "v1/sys_setting/all", Setting.class, true),    // 获取全局配置
    reqNewVersion(Hosts.FATE_IT_GO, "v1/sys_setting/upgrade", Updata.class, false),    // 检查更新
    reqFeedBack(Hosts.FATE_IT_GO, "v1/rec_feedback/add", null, true),    // 意见反馈
    uploadFile(Hosts.FATE_IT_OSS, "v1/fun_utils/upload", UpLoadResult.class, true),    // 上传文件
    deleteFile(Hosts.FATE_IT_OSS, "v1/fun_utils/delete", null, true),                   // 删除文件
    reqShareAdd(Hosts.FATE_IT_GO, "v1/user_detail/share", null, false),  // 分享奖励调用

    reqSendCode(Hosts.FATE_IT_GO, "v1/user_login/send_code", null, false),               // 获取登录验证码
    reqLogin(Hosts.FATE_IT_GO, "v1/user_login/login", LoginResult.class, false),  // 用户登录：手机，QQ，微信
    getWXAccessToken(ThirdConstant.WECHAT_API_SERVER, "oauth2/access_token", null, false),    // 获取微信AccessToken
    getWXUserInfo(ThirdConstant.WECHAT_API_SERVER, "userinfo", null, false),                  // 获取微信用户资料
    reqModifyInfo(Hosts.FATE_IT_GO, "v1/user_detail/update", null, true),    // 自由修改用户个人信息
    reqMyInfo(Hosts.FATE_IT_GO, "v1/user_detail/", UserDetail.class, true),      // 获取个人资料

    // ================= 资产管理 ===========================
    reqWithdraw(Hosts.FATE_IT_GO, "v1/rec_amount/cash", null, true),       // 提现申请
    reqWalletDetail(Hosts.FATE_IT_GO, "v1/rec_amount/list", IncomeList.class, true),        // 收益明细列表

    reqDiamondList(Hosts.FATE_IT_GO, "v1/sys_do/all", DiamondList.class, true),        // 获取钻石充值列表
    reqDiamondDetail(Hosts.FATE_IT_GO, "v1/rec_do/list", DiamondList.class, true),        // 钻石明细列表
    reqVipPrivilege(Hosts.FATE_IT_GO, "v1/sys_vip_right/all", PrivilegeList.class, true),    // 获取Vip特权列表
    reqVipList(Hosts.FATE_IT_GO, "v1/sys_vip/all", VipList.class, true),    // 获取Vip充值列表

    reqInviteDeclare(Hosts.FATE_IT_GO, "v1/sys_invite/all", InviteDeclareList.class, true),    // 邀请说明列表
    reqInviteExchange(Hosts.FATE_IT_GO, "v1/rec_do/exchange", null, true),    // 男性： 邀请收益兑换钻石
    reqInviteDetail(Hosts.FATE_IT_GO, "v1/rec_invite/list", InviteDetailList.class, true),    // 邀请明细
    reqExchangeRule(Hosts.FATE_IT_GO, "v1/user_detail/exchange", null, true),    // 兑换钻石：当前金额即可兑换钻石数

    reqPayAdd(Hosts.FATE_IT_GO, "v1/fun_pay/add", Pay.class, true),    // 支付接口

    // ================= 用户关系 ===========================
    getUserRelation(Hosts.FATE_IT_GO, "v1/rec_friend/list", UserLightList.class, true),     //获取好友列表
    getHasChat(Hosts.FATE_IT_GO, "v1/rec_friend/chat", UserLightList.class, true),     //获取聊过的人
    getMyRequestFriends(Hosts.FATE_IT_GO, "v1/rec_friend/request", UserLightList.class, true),     //获取好友列表
    setUserRelation(Hosts.FATE_IT_GO, "v1/rec_friend/status", null, true),    // 改变好友关系 加好友、删除、加黑名单

    // ================ 音视频相关 ==========================
    reqChatQualified(Hosts.FATE_IT_GO, "v1/rec_chat/book", null, true),      // 男号：检测是否可以发起聊天 女号：检测对方是否可以聊天
    reqAcceptChat(Hosts.FATE_IT_GO, "v1/rec_chat/accept", Accept.class, true), // 接受通信邀请
    reqStopChat(Hosts.FATE_IT_GO, "v1/rec_chat/end", null, true),// 挂断聊天
    reqChatStart(Hosts.FATE_IT_GO, "v1/rec_chat/start", ChatStatus.class, true),            // 男号调用： 加入频道成功，通知服务端
    reqCheckChat(Hosts.FATE_IT_GO, "v1/rec_chat/check", ChatStatus.class, true),// 男号调用： 聊天中，客户端刷新聊天状态（轮询接口）
    reqGetFeedbackInfo(Hosts.FATE_IT_GO, "v1/sys_label/all", LabelList.class, true),// 男性：获取视频评价信息
    reqAddFeedback(Hosts.FATE_IT_GO, "v1/rec_chat/star", null, true),     // 男性： 视频评价
    getGiftLists(Hosts.FATE_IT_GO, "v1/sys_gift/all", GiftsList.class, true),            // 获取礼物列表
    reqSendGift(Hosts.FATE_IT_GO, "v1/rec_gift/add", null, true),            // 赠送礼物
    reqGetGift(Hosts.FATE_IT_GO, "v1/rec_gift/list", GiftsList.class, true),            // 用户收到的礼物
    reqGetComplainReasons(Hosts.FATE_IT_GO, "v1/sys_report/all", RtcComplainReasons.class, true), // 视频中投诉列表
    reqAddComplaint(Hosts.FATE_IT_GO, "v1/rec_report/add", null, true),       // 投诉

    reqGirlRand(Hosts.FATE_IT_GO, "v1/user_detail/rand", UserLightList.class, true),  // 随机获取女聊昵称头像
    reqChatAdd(Hosts.FATE_IT_GO, "v1/rec_chat/add", null, true),       // 男性： 发起群聊天
    reqChatCancel(Hosts.FATE_IT_GO, "v1/rec_chat/cancel", null, true),       // 男性： 取消发起群聊
    reqChatPool(Hosts.FATE_IT_GO, "v1/rec_chat/pool", RobList.class, true),  // 女性：抢聊大厅聊天池
    reqChatGrab(Hosts.FATE_IT_GO, "v1/rec_chat/grab", null, true),           //  女性： 抢占聊天
    reqSysAward(Hosts.FATE_IT_GO, "v1/sys_star/all", PointList.class, true),  //  女性： 评分与奖励

    // ================= 聊天消息  ============================
    sendMessage(Hosts.FATE_IT_MSG, "send_msg/", null, true),      // 发送消息走Http短连接
    reqOfflineMsg(Hosts.FATE_IT_GO, "v1/rec_msg/list", OfflineMsg.class, true), // 离线消息

    // ========================================================== 以下接口暂时保留 ==============================================================
    reqCheckPornography(Hosts.FATE_IT_GO, "index/message/CheckPornography", null, true), // 视频聊天鉴黄接口
    reqGetPropList(Hosts.FATE_IT_GO, "xs/message/GetPropList", RtcProps.class, true),

    //================================ 配置项 ==================================
    CMDRequest(""),//cmd请求中默认拼接内容为空，通过resetHost方式进行使用

    // 最后一个，占位
    LastUrlParam("");

    // -------------------------------内部处理逻辑----------------------------------------

    private String host = Hosts.HOST_URL;    //请求host
    private String spliceUrl = null;            //接口url，与host拼接得到完整url
    private boolean needLogin = false;          //请求是否需要登录才会发送
    private Class<? extends BaseData> parseClass = null;//请求返回体解析类

    // --------------构造方法 start--------------

    /**
     * host+接口url+解析bean
     */
    UrlParam(final String host, final String spliceUrl, final Class<? extends BaseData> parseClass, final boolean needLogin) {
        this.host = host;
        this.spliceUrl = spliceUrl;
        this.parseClass = parseClass;
        this.needLogin = needLogin;
    }

    /**
     * 接口url+解析bean+是否需要登录
     */
    UrlParam(final String spliceUrl, final Class<? extends BaseData> parseClass, final boolean needLogin) {
        this(Hosts.HOST_URL, spliceUrl, parseClass, needLogin);
    }

    /**
     * 接口url+解析bean
     */
    UrlParam(final String spliceUrl, final Class<? extends BaseData> parseClass) {
        this(spliceUrl, parseClass, false);
    }

    /**
     * 接口url+是否需要登录
     */
    UrlParam(final String spliceUrl, final boolean needLogin) {
        this(spliceUrl, null, needLogin);
    }

    /**
     * 接口url
     */
    UrlParam(final String spliceUrl) {
        this(spliceUrl, null);
    }

    // --------------构造方法 end--------------

    /**
     * 重设请求host
     *
     * @param host host地址
     * @return UrlParam
     */
    public UrlParam resetHost(String host) {
        this.host = host;
        return this;
    }

    /**
     * 重设接口url，特殊情况使用
     *
     * @param spliceUrl 接口url
     */
    public void resetSpliceUrl(String spliceUrl) {
        this.spliceUrl = spliceUrl;
    }

    /**
     * 是否需要登录才能发送的请求
     *
     * @return boolean值
     */
    public boolean isNeedLogin() {
        return needLogin;
    }

    /**
     * 获取完整Url
     *
     * @return url
     */
    public String getFinalUrl() {
        if (host.equals(Hosts.NO_HOST)) {
            return spliceUrl;
        }
        return host + spliceUrl;
    }

    /**
     * 获取一个实现了BaseData接口的实例
     *
     * @return 有Class的newInstance生成的实例
     */
    public BaseData getBaseData() {
        BaseData baseData = null;
        try {
            if (parseClass != null) baseData = parseClass.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return baseData;
    }

    /**
     * 获取完整拼接参数的Url，用于缓存url等
     *
     * @param param 需要传送的参数
     * @return spliceUrl
     */
    public String getEntireUrl(Map<String, Object> param) {
        String url = this.spliceUrl;
        if (param != null) {
            for (Object o : param.entrySet()) {
                Map.Entry entry = (Map.Entry) o;
                Object key = entry.getKey();
                Object val = entry.getValue();
                url = url.replaceAll("\\{" + key.toString() + "\\}", val.toString());
            }
        }
        if (!host.equals(Hosts.NO_HOST)) {
            url = host + url;
        }
        return url;
    }
}